﻿//Author: Paweł Kaftan
using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;

namespace HamiltonianCycle
{
    partial class Program
    {
        static void Main(string[] args)
        {
            int graphsInLoop = 100;
            long maxTime = 0;
            int testedGraphs = 0;
            Stopwatch Sw;
            maxTime = 0;
            for (int size = 10; size < 125; ++size)
                for (int a = 0; a < 100; ++a)
                {
                    List<int>[] graph = CreateGraph(size, (double)a / graphsInLoop, false, true, true);
                    //List<int>[] graph = LoadGraphFromFile("1.txt");
                    //SaveGraphToFile("1.txt", graph);
                    //WriteGraph(graph);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(DateTime.Now.ToLongTimeString() + " | Graph nr " + (++testedGraphs).ToString() + " Density: " + GraphDensityInPercent(graph).ToString()
                                      + "% " + "Vertices: " + graph.Length + " Edges: " + NumberOfEdges(graph));
                    Sw = Stopwatch.StartNew();
                    List<int> HamiltonianCycle = Algorithm(graph);
                    Sw.Stop();
                    if (Sw.ElapsedMilliseconds > maxTime)
                        maxTime = Sw.ElapsedMilliseconds;
                    Console.Write("Result found in: " + String.Format("{0:0.000}", Convert.ToDouble(Convert.ToDouble(Sw.ElapsedMilliseconds) / 1000.0)) + " seconds. Result: ");
                    if (HamiltonianCycle.Count == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("no Hamiltonian cycle found");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Hamiltonian cycle was found");
                        if (!CheckCorrectnessOfFoundHamiltonianCycle(graph, HamiltonianCycle))
                        {
                            Console.WriteLine("Error");
                            Console.ReadKey();
                        }
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Max time: " + String.Format("{0:0.000}", Convert.ToDouble(Convert.ToDouble(maxTime) / 1000.0)) + " seconds\n");
                }
            Console.ReadKey();
        }
    }
}